import time
import datetime

# 时间转时间字符串
def date_to_str(date, fmt='%Y-%m-%d'):
    return date.strftime(fmt)


# 时间字符串转时间戳 18位
def time_str_to_stamp(time_str, fmt='%Y-%m-%d', length=13):
    time_str = time.strptime(time_str, fmt)
    timestamp = str(int(time.mktime(time_str)))
    while len(timestamp) < length:
        timestamp += '0'
    return timestamp


def date_to_timestamp(date, length=13):
    to_str = date_to_str(date)
    stamp = time_str_to_stamp(to_str)
    return stamp
if __name__ == '__main__':
    # import time
    #

    current_timestamp1 = datetime.datetime.now().timestamp()
    current_timestamp = time.time()
    print(date_to_str(datetime.datetime.now(),'%Y%m%d%H%M%S'))